package controllers;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.sql.Time;                                                                                                                                                                                                                                                        

import objects.Status;

public class AddState {
	public AddState(Status status){
		this.status = status;
		this.add();
	}
	Status status;
	public int add(){
		int result = 0;
        try{
        	//URL url = new URL("http://shangwangba.info");
			URL url=new URL("http://localhost:8081/AngryFishWeb/servlet/AddState?Id="+status.getId()+"&time="+status.getDate()+"%20"+status.getTime()+"&content="+status.getContent());
			BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
			               //http://localhost:8081/AngryFishWeb/servlet/AddState?Id=d08i08&time=2020-02-22%2012:23:21&content=sdff
			//System.out.println(status.getTime()+""+status.getContent());
			/*URLConnection conn=url.openConnection();
			BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));*/
			String line=null;
			while((line=reader.readLine())!=null){
			//line=reader.readLine();
				if(line.equals("Add successfully!")){
					result = 1;
					System.out.println(line);
				}
				
			}
					//System.out.println(line);
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}

/*public static void main(String[] args){
	AddState addStatus = new AddState();
	addStatus.status.setId("7e389121");
	addStatus.status.setContent("fjdifj");
	Date date = new Date();
	addStatus.status.setDate(new java.sql.Date(date.getTime()));
	addStatus.status.setTime(new Time(date.getTime()));
	addStatus.add();
	System.out.println(addStatus.status.getStatusId());
}*/
}